package com.example.btmac;

import java.util.List;

import com.example.btmac.R;

import bean.BlueBean;
import utils.BlueUtils;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BlueAdapter2 extends BaseAdapter {
	
	private Context mContext;
	private List<BlueBean> mList;

	public BlueAdapter2(Context context,List<BlueBean> list){
		this.mContext = context;
		this.mList = list;
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup group) {
		ViewHolder holder;
		
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item, null);
			holder.name = (TextView) convertView.findViewById(R.id.item_name);
			holder.mac = (TextView) convertView.findViewById(R.id.item_mac);
			holder.type = (TextView) convertView.findViewById(R.id.item_type);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		BlueBean bean = mList.get(position);
        //名称
        holder.name.setText(bean.getBlueName());
        //mac
		holder.mac.setText(bean.getBlueMac());
		//设备类型
		holder.type.setText(bean.getBlueType());
		
		return convertView;
	}
	
	static class ViewHolder{
		TextView name;
		TextView mac;
		TextView type;
	}

}
